﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using myBoard.App.MagnetStore;
using myBoard.App.Components.MagnetsStore.ViewsModels;

namespace myBoard.App.Components.MagnetsStore
{
    /// <summary>
    /// Interaction logic for MagnetReview.xaml
    /// </summary>
    public partial class MagnetReview : UserControl
    {
        public delegate void ReturnToMagnetDetailsRequestedHandler(MagnetReview sender);
        public event ReturnToMagnetDetailsRequestedHandler ReturnToMagnetDetailsRequested;
        public delegate void SubmitCommentRequestedHandler(MagnetComment comment);
        public event SubmitCommentRequestedHandler SubmitCommentRequested;

        public MagnetViewModel ForMagnet
        {
            get { return (MagnetViewModel)GetValue(ForMagnetProperty); }
            set { SetValue(ForMagnetProperty, value); }
        }

        public static readonly DependencyProperty ForMagnetProperty =
            DependencyProperty.Register("ForMagnet", typeof(MagnetViewModel), typeof(MagnetReview), new UIPropertyMetadata(ForMagnetChanged));

        private static void ForMagnetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            
        } 

        public MagnetReview()
        {
            InitializeComponent();
            _returnToMagnetBt.Click += new RoutedEventHandler(_returnToMagnetBt_Click);
            _submitCommentBt.Click += new RoutedEventHandler(_submitCommentBt_Click);
            _submitCommentControl.CancelCommentRequested += new SubmitCommentControl.CancelCommentRequestedHandler(_submitCommentControl_CancelCommentRequested);
            _submitCommentControl.SubmitCommentRequested += new SubmitCommentControl.SubmitCommentRequestedHandler(_submitCommentControl_SubmitCommentRequested);
        }

        void _submitCommentControl_SubmitCommentRequested(myBoard.App.MagnetStore.MagnetComment comment)
        {
            _submitCommentControl.Visibility = Visibility.Collapsed;
            _submitCommentBt.Visibility = Visibility.Visible;

            if (SubmitCommentRequested != null)
                SubmitCommentRequested(comment);
        }

        void _submitCommentControl_CancelCommentRequested(SubmitCommentControl sender)
        {
            _submitCommentControl.Visibility = Visibility.Collapsed;
            _submitCommentBt.Visibility = Visibility.Visible;
        }

        void _submitCommentBt_Click(object sender, RoutedEventArgs e)
        {
            if (_submitCommentControl.Visibility == Visibility.Collapsed)
            {
                _submitCommentControl.Visibility = Visibility.Visible;
                _submitCommentBt.Visibility = Visibility.Collapsed;
            }
        }

        void _returnToMagnetBt_Click(object sender, RoutedEventArgs e)
        {
            if (ReturnToMagnetDetailsRequested != null)
                ReturnToMagnetDetailsRequested(this);
        }
    }
}
